:Init
@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@prompt $_
@echo off

:Vars
if not "%~fp1"=="" set "_TestSitesFolder=%~fp1"
if "%_TestSitesFolder%"=="" (
	@echo Using temp folder: "%TEMP%"
	set "_TestSitesFolder=%TEMP%\_TestSites"
	)
@echo Root Site Folder:      %_TestSitesFolder%
if not exist "%_TestSitesFolder%" (
	@echo Creating Directory:    %_TestSitesFolder%
	md "%_TestSitesFolder%"
) else (
	@echo Directory Verified:    %_TestSitesFolder%
)

@if not exist "%_TestSitesFolder%" md "%_TestSitesFolder%"

:CreateSites
call :CreateApplication "%_TestSitesFolder%\s1" "Site 1"
call :CreateApplication "%_TestSitesFolder%\s2" "Site 2"
call   :CreateDirectory "%_TestSitesFolder%\vd1s2" "vDir 1 on Site 2"
call   :CreateDirectory "%_TestSitesFolder%\vd2s2" "vDir 2 on Site 2"
call     :CreateDirectory "%_TestSitesFolder%\vd1vd2s2" "vDir 1 of vDir 2 on Site 2"
call   :CreateApplication "%_TestSitesFolder%\va1s2" "vApp 1 on Site 2"
call   :CreateApplication "%_TestSitesFolder%\va2s2" "vApp 2 on Site 2"
call     :CreateApplication "%_TestSitesFolder%\va1va2s2" "vApp 1 of vApp 2 on Site 2"
call :CreateApplication "%_TestSitesFolder%\s3" "Site 3"
@goto :End

:CreateDirectory
if not exist "%~fp1" (
	@echo Creating Directory:    %~fp1
	md "%~fp1"
) else (
	@echo Directory Verified:    %~fp1
)
@call :CreateDefaultPage %1\default.html %2
@goto :eof

:CreateApplication
@echo Creating Application:  %~2
@call :CreateDirectory %1 %2
@call :CreateWebConfig %1\web.config %2
@goto :eof

:CreateWebConfig
@echo Creating Web.Config:   %~fp1
@echo ^<?xml version="1.0" encoding="UTF-8"?^> > "%~fp1"
@echo ^<configuration^> >> "%~fp1"
@echo     ^<system.webServer^> >> "%~fp1"
@echo         ^<defaultDocument enabled="true"^> >> "%~fp1"
@echo             ^<files^> >> "%~fp1"
@echo                 ^<clear /^> >> "%~fp1"
@echo                 ^<add value="default.html" /^> >> "%~fp1"
@echo             ^</files^> >> "%~fp1"
@echo         ^</defaultDocument^> >> "%~fp1"
@echo         ^<modules runAllManagedModulesForAllRequests="true" /^> >> "%~fp1"
@echo     ^</system.webServer^> >> "%~fp1"
@echo     ^<system.web^> >> "%~fp1"
@echo         ^<compilation debug="true" /^> >> "%~fp1"
@echo     ^</system.web^> >> "%~fp1"
@echo ^</configuration^> >> "%~fp1"
@goto :eof

:CreateDefaultPage
@echo Creating Default.htm:  %~fp1
@echo ^<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"^> > "%~fp1"
@echo ^<html xmlns="http://www.w3.org/1999/xhtml" ^> >> "%~fp1"
@echo ^<head^> >> "%~fp1"
@echo ^</head^> >> "%~fp1"
@echo ^<body^> >> "%~fp1"
@echo ^<h1^>%~2^</h1^> >> "%~fp1"
@echo ^</body^> >> "%~fp1"
@goto :eof

:End
@echo Complete.